package com.fulihui.usercore.core.repository.impl;

import com.fulihui.usercore.biz.conv.CooperationInfoConv;
import com.fulihui.usercore.condition.CooperationInfoCondition;
import com.fulihui.usercore.core.repository.CooperationInfoRepository;
import com.fulihui.usercore.dal.dataobj.CooperationInfoDO;
import com.fulihui.usercore.dal.mapper.CooperationInfoMapper;
import com.fulihui.usercore.dto.CooperationInfoDTO;
import com.fulihui.usercore.request.merchant.CooperationInfoSaveRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author Willard.Hu on 2016/9/25.
 */
@Repository
public class CooperationInfoRepositoryImpl implements CooperationInfoRepository {
    @Autowired
    private CooperationInfoMapper cooperationInfoMapper;

    @Override
    public int insert(CooperationInfoSaveRequest request) {
        CooperationInfoDO insert = CooperationInfoConv.toDO(request);
        cooperationInfoMapper.insert(insert);
        return insert.getId();
    }

    @Override
    public boolean update(CooperationInfoSaveRequest request) {
        return cooperationInfoMapper.update(CooperationInfoConv.toDO(request));
    }

    @Override
    public boolean delete(int id) {
        return cooperationInfoMapper.delete(id);
    }

    @Override
    public CooperationInfoDTO queryByPK(int id) {
        return CooperationInfoConv.toDTO(cooperationInfoMapper.queryByPK(id));
    }

    @Override
    public List<CooperationInfoDTO> query(CooperationInfoCondition condition) {
        List<CooperationInfoDO> doList = cooperationInfoMapper.query(CooperationInfoConv
            .toDO(condition));
        return CooperationInfoConv.toList(doList);
    }
}
